<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/logic/CustomCommand.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/DaoFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	/*
	* Class to validate a credential
	*/
	class CommandValidateCredential extends CustomCommand {
		/*
		* Constructor of the class
		*/
		public function __construct($username, $password) {
			$this -> username = $username;
			$this -> password = $password;
		}
		
		/*
		* Method to execute to validate the credential
		*/
		public function execute() {
			$daoFactory = DaoFactory :: getMySqlDaoFactory();
			$iuad = $daoFactory-> getMySqlUserAccessDao();			
			$sentence = $iuad -> validateUser($this -> username, $this -> password);
			
			$department = "false";
			while ($row = mysql_fetch_array($sentence)) {
				$department = $row['name'];
			}
			
			$this -> result = $department;
		}
	}
?>